<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>字幕资源管理</title>
	<meta name="decorator" content="default"/>

	<script src="${ctxStatic}/jquery-plugin/colpick.js" type="text/javascript"></script>
	<link href="${ctxStatic}/jquery-plugin/colpick.css" type="text/css" rel="stylesheet" />

	<script type="text/javascript">
		$(document).ready(function() {
           floorChange();
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('<spring:message code="common.subbmiting"/>');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});

			$(".color").colpick({
				layout:'hex',
				submit:0,
				colorScheme:'white',
				onChange:function(hsb,hex,rgb,el,bySetColor) {
					$(el).css('border-color','#'+hex);
					if(!bySetColor){
						$(el).val('#'+hex);
					}
				}
			}).keyup(function(){
				$(this).colpickSetColor(this.value);
			});
		});
		function addRow(list, idx, tpl, row){
            var floor = $("#toFloor").val();
            if(floor == "false"){
                tpl = tpl.replace("<td class=\"floor\">", "<td class=\"floor\" style=\"display: none\">");
            }else{
            }
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().parent().removeClass("error");
			}
		}


        function floorChange(){
			/* var id="imageGroup.toFloor";*/
            var floor = $("#toFloor").val();
            if(floor == "false"){
				/*  alert("aaaaaa")*/
                $('.floorval').val("");
                $(".floor").css("cssText", "display:none;");
				/*$(".floor").css("display","none");*/
//                $("#videoSource").attr("style","display:visible");
            }else{

				/* alert("aaaavvvvvvvvvvvaa")*/
                $(".floor").css("cssText", "display:visible;");
				/*  $("#videoSource").attr("style","display:none");*/
            }
        }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/subtitle/eleSourceSubtitleGroup/">字幕资源列表</a></li>
		<li class="active"><a href="${ctx}/source/subtitle/eleSourceSubtitleGroup/form?id=${eleSourceSubtitleGroup.id}">字幕资源<shiro:hasPermission name="source:subtitle:eleSourceSubtitleGroup:edit">${not empty eleSourceSubtitleGroup.id?'<spring:message code="common.modify"/>':'<spring:message code="common.add"/>'}</shiro:hasPermission><shiro:lacksPermission name="source:subtitle:eleSourceSubtitleGroup:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceSubtitleGroup" action="${ctx}/source/subtitle/eleSourceSubtitleGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="25" class="input-large required"/>
												<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">字体大小：</label>
			<div class="controls">
				<form:input path="fontsize" htmlEscape="false" class="input-small digits"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">显隐：</label>
			<div class="controls">
				<form:select path="area" class="input-small ">
					<form:options items="${fns:getDictList('truefalse')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>			</div>
		</div>
		<div class="control-group">
			<label class="control-label">文字颜色：</label>
			<div class="controls">
				<form:input path="fgcolor" htmlEscape="false" maxlength="255" class="input-small color"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">背景颜色：</label>
			<div class="controls">
				<form:input path="bgcolor" htmlEscape="false" maxlength="255" class="input-small color"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">背景图片：</label>
			<div class="controls">
				<form:hidden id="bgimage" path="bgimage" htmlEscape="false" maxlength="255" class="input-xlarge"/>
				<sys:ckfinder input="bgimage" type="files" uploadPath="/source/subtitle/eleSourceSubtitleGroup" selectMultiple="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">滚动速度：</label>
			<div class="controls">
				<form:select path="speed" class="input-small">
					<c:forEach begin='0' end='10' var="i">
						<c:if test="${eleSourceSubtitleGroup.speed ==i }">
						<option value="${i}" selected>${i}</option>
						</c:if>
						<c:if test="${eleSourceSubtitleGroup.speed !=i }">
						<option value="${i}">${i}</option>
						</c:if>
					</c:forEach>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">文字滚动方向：</label>
			<div class="controls">
				<form:select path="orientation" class="input-small ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('scroll_orientation')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">对应楼层：</label>
			<div class="controls">
				<form:select path="toFloor" class="input-small " onchange="floorChange();">
					<form:options items="${fns:getDictList('truefalse')}" itemLabel="label"
                                  itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<%--<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>--%>
			<div class="control-group">
				<label class="control-label">字幕资源：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>字幕的名字</th>
								<th>字幕的内容</th>
								<th class="floor">对应的楼层</th>
								<%--<th><spring:message code='common.remarks'/></th>--%>
								<shiro:hasPermission name="source:subtitle:eleSourceSubtitleGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="eleSourceSubtitleList">
						</tbody>
						<shiro:hasPermission name="source:subtitle:eleSourceSubtitleGroup:edit"><tfoot>
							<tr><td colspan="6"><a href="javascript:" onclick="addRow('#eleSourceSubtitleList', eleSourceSubtitleRowIdx, eleSourceSubtitleTpl);eleSourceSubtitleRowIdx = eleSourceSubtitleRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eleSourceSubtitleTpl">//<!--
						<tr id="eleSourceSubtitleList{{idx}}">
							<td class="hide">
								<input id="eleSourceSubtitleList{{idx}}_id" name="eleSourceSubtitleList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceSubtitleList{{idx}}_delFlag" name="eleSourceSubtitleList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="eleSourceSubtitleList{{idx}}_name" name="eleSourceSubtitleList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="255" class="input-small "/>
							</td>
							<td>
								<textarea id="eleSourceSubtitleList{{idx}}_text" name="eleSourceSubtitleList[{{idx}}].text" rows="1" maxlength="255" class="input-small ">{{row.text}}</textarea>
							</td>
							<td class="floor">
								<input id="eleSourceSubtitleList{{idx}}_correspondingFloor" name="eleSourceSubtitleList[{{idx}}].correspondingFloor" type="text" value="{{row.correspondingFloor}}" maxlength="255" class="input-small digits floorval"/>
							</td>
							<%--<td>
								<textarea id="eleSourceSubtitleList{{idx}}_remarks" name="eleSourceSubtitleList[{{idx}}].remarks" rows="2" maxlength="255" class="input-small ">{{row.remarks}}</textarea>
							</td>--%>
							<shiro:hasPermission name="source:subtitle:eleSourceSubtitleGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceSubtitleList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceSubtitleRowIdx = 0, eleSourceSubtitleTpl = $("#eleSourceSubtitleTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceSubtitleGroup.eleSourceSubtitleList)};
							for (var i=0; i<data.length; i++){
								addRow('#eleSourceSubtitleList', eleSourceSubtitleRowIdx, eleSourceSubtitleTpl, data[i]);
								eleSourceSubtitleRowIdx = eleSourceSubtitleRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
		<div class="form-actions">
			<shiro:hasPermission name="source:subtitle:eleSourceSubtitleGroup:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>